//
//  ScenesFoaBinauralizer.h
//  ScenesPlayer
//
//  Created by Branch on 2017/5/2.
//  Copyright © 2017年 Scenes. All rights reserved.
//

#ifndef __ScenesPlayer_ScenesFoaBinauralizer_H__
#define __ScenesPlayer_ScenesFoaBinauralizer_H__

#include <stdint.h>

#include "kissfft/kiss_fftr.h"
/**
 把4声道的声场混合成立体声
 */

class ScenesFoaBinauralizer {

public:
	ScenesFoaBinauralizer();
	~ScenesFoaBinauralizer();
    
    bool open(uint32_t nsamples);
    
    void close();
    
    bool processAudio(float** src,float** dest);
  
    
private:
    void allocateBuffers();
    void deallocateBuffers();
    void initOmnitoneFilters();

private:

    float* _pfScratchBuffer;
    float* _pfScratchBufferL;
    float* _pfScratchBufferR;
    uint32_t _nFFTSize;
    uint32_t _nFFTBins;
    
    float* _pfOverlapL;
    float* _pfOverlapR;
    
    uint32_t _nsamples;
    
    uint32_t _nOverlapLength;
    
    

    kiss_fftr_cfg _pFFT_cfg;
    kiss_fftr_cfg _pIFFT_cfg;
    
    kiss_fft_cpx* _pcpScratch;
    
    kiss_fft_cpx* _omnitoneFilters[4];
    uint32_t _nTaps;
    
    
    float _fFFTScaler;
    int _isFirst;          //第一帧不给声音，避免爆音
    
};


#endif /* __ScenesPlayer_ScenesFoaBinauralizer_H__ */
